<?php

class adminDigitalContent extends Controller
{

	public function index()
    {
    	// Verify if admin is logge in, otherwise redirect out
    	Helper::verifyAdminLoggedIn();
    	
	    $digitalContents = $this->model->getAllDigitalContent();
		$categories = $this->model->getCategories();
	    //print "Categories Are : <pre>" . print_r($categories,true) . "</pre>";exit;
        //$amount_of_digitalContents = $this->model->getamoutDigitalContent();
     
	
        // load views
        require APP . 'views/admin_templates/header.php';
        require APP . 'views/adminDigitalContent/index.php';
        require APP . 'views/admin_templates/footer.php';
    }
	 
	
	 
    public function addDigitalContent()
    {
    	$result = 0;
    	// Verify if admin is logge in, otherwise redirect out
    	Helper::verifyAdminLoggedIn();
    	
    	//print "<pre>" . print_r($_POST , true ) . "<pre>";
    	//print "<pre>" . print_r($_FILES , true ) . "<pre>";

        if (isset($_POST["submit_add_DigitalContent"])) {
        	
        	$image = $this->model->uploadFile($_FILES);
            $result = $this->model->addDigitalContent($_POST["title_en"],$_POST["title_ar"],$_POST["keywords_en"],$_POST["keywords_ar"],$_POST["historical_importance_en"],$_POST["historical_importance_ar"],$_POST["tags_en"],$_POST["tags_ar"],$_POST["geo_lat"],$_POST["geo_lon"],$_POST["category_id"],$image);
         }
		header('location: ' . URL . 'adminDigitalContent?result='.$result);
		
	}
	
	public function deleteDigitalContent($digital_content_id)
    {
		// Verify if admin is logge in, otherwise redirect out
    	Helper::verifyAdminLoggedIn();
    	
        if (isset($digital_content_id)) {
            $this->model->deleteDigitalContent($digital_content_id);
        }

        header('location: ' . URL . 'adminDigitalContent');
    }

	public function updateDigitalContent()
    {
    	// Verify if admin is logge in, otherwise redirect out
    	Helper::verifyAdminLoggedIn();

        if (isset($_POST["submit_update_DigitalContent"])) {
            $this->model->updateDigitalContent($_POST["title_en"],$_POST["title_ar"],$_POST["keywords_en"],$_POST["keywords_ar"],$_POST["historical_importance_en"],$_POST["historical_importance_ar"],$_POST["tags_en"],$_POST["tags_ar"],$_POST["geo_lat"],$_POST["geo_lon"],$_POST["category_id"],$_POST["digital_content_id"]);
        }

        header('location: ' . URL . 'adminDigitalContent/editDigitalContent/'.$_POST["digital_content_id"]);
    }
	

	public function editDigitalContent($digital_content_id)
    {
    	// Verify if admin is logge in, otherwise redirect out
    	Helper::verifyAdminLoggedIn();

        if (isset($digital_content_id)) {
        	$categories = $this->model->getAllCategories();
            $digital_content = $this->model->getDigitalContent($digital_content_id);
            // load views
	        require APP . 'views/admin_templates/header.php';
			require APP . 'views/adminDigitalContent/edit.php';
	        require APP . 'views/admin_templates/footer.php';
            
        } else {
            header('location: ' . URL . 'adminDigitalContent/index');
        }
    }
}
